import {
	getTypeList
} from "./config"

// 格式化分类显示的名字
const formatShowClassName = (classnames) => {
	let sn = ""
	const arrs = classnames.split("#")
	arrs.forEach((m, i) => {
		if (m !== "" && i > 0 && i < arrs.length - 1) {
			sn += m
			if (i < arrs.length - 2) {
				sn += "   >   "
			}

		}
	})
	return sn
}


// 格式化分类显示的名字
const getTypeColor = (id) => {
	let color = ''
	const ss = getTypeList()
	for (let i in ss) {
		if (ss[i].id === id) {
			color = ss[i].lineColor
		}
	}
	return color
}

// 流水每日汇总信息
const getJournalDayTotal = (lst) => {

	let zc = 0
	let sr = 0

	for (let i in lst) {
		const item = lst[i]
		if (item.typid === "1") {
			zc += item.amount
		} else if (item.typid === "2") {
			sr += item.amount
		}
	}

	return ('支: ' + zc.toFixed(2)) + ('  收: ' + sr.toFixed(2))
}

// 流水每月汇总信息
const getJournalMonthTotal = (lst) => {

	let zc = 0
	let sr = 0

	for (let i in lst) {
		const item = lst[i]
		if (item.typid === "1") {
			zc += item.amount
		} else if (item.typid === "2") {
			sr += item.amount
		}
	}

	return {zc,sr}
}


// +-
const getTypeSymbol = (id) => {
	switch (id) {
		case '1':
			return '-'
			break
		case '2':
			return '+'
			break
	}
}





export {
	formatShowClassName,
	getTypeColor,
	getJournalDayTotal,
	getTypeSymbol,
	getJournalMonthTotal,
}